home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / C_BAR1.ARJ / BAR.C next >
C/C++ Source or Header  |  1992-02-27  |  2KB  |  68 lines

  1. /*
  2.  * bar - print barcode, 3-of-9, external printer interface
  3.  * written 1987 David J. Rodman
  4.  * Paradise Technology, Inc.
  5.  * Compuserve 70007,1545
  6.  * (808) 326-9556
  7.  * This code is placed into the public domain.  Have at it.
  8.  */
  9. #include <stdio.h>
  10.  
  11. int res = 2;              /* resolution, horizontal */
  12. int depth = 4;            /* lines deep to print pattern */
  13. int lineno;
  14. #define BFSIZ 512
  15.  
  16. extern prbar();            /* print thick or thin line or space */
  17. extern prinit(), prfini(), prdown();    /* initialize, finish, move down */
  18.  
  19.  
  20. /*
  21.  * These codes represent the 3-of-9 encoding.  Note that there are exactly
  22.  *    three 1-bits in each code.  Those are the "thick" lines/spaces.  
  23.  *    The barcode alternates between lines and spaces - the codes below
  24.  *    determine the width of each line or space, not whether it's a line
  25.  *    or a space.
  26.  */
  27. static unsigned codes[] = 
  28. {    0xc4, 0, 0, 0, 0xa8, 0x2a, 0, 0, 0, 0, 0, 0x8a, 0, 0x85, 0x184, 0xa2,
  29.     0x34, 0x121, 0x61, 0x160, 0x31, 0x130, 0x70, 0x25, 0x124, 0x64, 0, 0, 0, 0, 0, 0, 0,
  30.     0x109, 0x49, 0x148, 0x19, 0x118, 0x58, 0x0d, 0x10c, 0x4c, 0x1c,
  31.     0x103, 0x43, 0x142, 0x13, 0x112, 0x52, 7, 0x106, 0x46, 0x16, 0x181, 0x0c1,
  32.     0x1c0, 0x91, 0x190, 0x0d0
  33. };
  34.  
  35. /*
  36.  * text[0] is printed on the bottom line of the label, after the barcode.
  37.  * text[1-10] is printed at the right of the barcode on each line 1-depth
  38.  */
  39. char *text[] = {"", "", "", "", "", "", "", "", "", "", ""};
  40.  
  41. bar(str)
  42.     char *str;            /* string to be printed */
  43. {
  44.     int i;
  45.     char *s;
  46.  
  47.     lineno = 1;
  48.     for(i = depth; i--; prdown())
  49.     {    prinit(s = str);
  50.         barc(0x94);            /* start code */
  51.         while(*s)
  52.             barc(codes[*s++ - ' ']);
  53.         barc(0x94);            /* stop code */
  54.     }
  55.     prfini();
  56. }
  57.  
  58. static barc(c)
  59. {
  60.     int line;            /* BOOL line/space */
  61.     unsigned mask;
  62.  
  63.     for(line = 1, mask = 0x100; mask; mask >>= 1, line = 1 - line)
  64.         prbar(c & mask, line);
  65.     prbar(0, 0);        /* finish each char with a thin space */
  66. }
  67.  
  68.